package fr.utbm.aiechat.activities;

import fr.utbm.aiechat.Network;
import fr.utbm.aiechat.structures.Conversation;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class ConvsTabActivity extends ListActivity
{
	Conversation conversSelected = null;
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setListAdapter(Network.getInstance().Conversations);
		
		final ListView lv = getListView();
		lv.setTextFilterEnabled(true);

		//lv.setOnItemClickListener(Network.getInstance().Conversations);
		lv.setOnItemClickListener(new OnItemClickListener()
		{
			public void onItemClick(AdapterView<?> parent, View view,int position, long id)
			{
				conversSelected = (Conversation) lv.getItemAtPosition(position);
				Bundle b = new Bundle();
    			b.putInt("chanSelected", conversSelected.getChannel().getUniqueID());
    			Intent MessActivity = new Intent(getBaseContext(), MessActivity.class);
    			MessActivity.putExtras(b);
            	startActivity(MessActivity);
			}
		});
	}
	/*protected Dialog onCreateDialog(final int id)
	{
	    Dialog dialog;
	    	
    	final CharSequence[] items = {"Lancer Conversation","Voir Infos"};
		AlertDialog.Builder builder = new AlertDialog.Builder(ConvsTabActivity.this);
		builder.setTitle("Actions");
		builder.setItems(items, new DialogInterface.OnClickListener() {
		    public void onClick(DialogInterface dialog, int item) {
		    	switch (item) {
		    		case 0 : 
		    			Bundle b = new Bundle();
		    	        System.out.println("chanObject = " + conversSelected.getChannel());
		    			b.putInt("chanSelected", conversSelected.getChannel().getUniqueID());
		    			Intent MessActivity = new Intent(getBaseContext(), MessActivity.class);
		    			MessActivity.putExtras(b);
		            	startActivity(MessActivity);
		    		break;
		    		
		    	}
		        Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
		    }
		});
		dialog = builder.create();
	    return dialog;
	}*/
}
